package Base;

import javafx.beans.binding.When;

/**
 * <p>Title Sort</p>
 *
 * @author YiMing Liu
 * @date 2018/7/10 20:59
 * <p>Description:</p>
 */
public class Sort {

   /* 冒泡排序
   public static void main(String[] args) {
        int[] a = {3, 4, 1, 6, 2};
        bubbleSrot(a, a.length);
       for (int n : a){
           System.out.println(n);
       }
    }
    public static void bubble(int a[], int n) {
        for (int i = 0; i < n - 1; i++) {
            if (a[i] > a[i + 1]) {
                int temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
            }
        }
    }
    public static void bubbleSrot(int a[], int n) {
        for (int i = n; i >= 1; i--) {
            bubble(a, n);
        }
    }*/

    // 选择排序
  /* public static void main(String[] args) {
        int[] a = {3, 4, 1, 6, 2};
        selectSort(a, a.length);
        for (int n : a) {
            System.out.print(n);
        }
    }

    public static int findMaxIndex(int a[], int n) {
        int max = a[0];
        int index = 0;
        for (int i = 0; i < n; i++) {
            if (max < a[i]) {
                max = a[i];
                index = i;
            }
        }
        return index;
    }

    public static void selectSort(int[] a, int n) {
        while (n > 1) {
            int maxIndex = findMaxIndex(a, n);
            int temp = a[maxIndex];
            a[maxIndex] = a[n - 1];
            a[n - 1] = temp;
            n--;
        }
    }
*/

   /* public static void main(String[] args) {
        int[] a = {3, 4, 1, 6, 2};
        insertSort(a);
        for (int n : a) {
            System.out.print(n);
        }
    }

    public static void insertSort(int[] a) {
        int key, j;
        for (int i = 1; i < a.length; i++) {
            key = a[i];
            j = i - 1;
            while ((j >= 0) && key < a[j]) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = key;
        }
    }*/


    public static void main(String[] args) {
        int[] a = {7, 5, 3, 1, 6};
        SortUtil.bubbleSort(a,a.length);
        for (int n : a) {
            System.out.print(n + " ");
        }
    }
}





